package com.example.demo.config;

import com.example.demo.util.UserContext;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.HandlerInterceptor;
public class Interceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        if (handler instanceof HandlerMethod){
            try {
                String token = request.getHeader("token");
                Long id = parseToken(token);
                UserContext.setUser(id);
                return true;
            } catch (Exception e) {
                throw new RuntimeException(e);
            }

        }
        return true;

    }
    private Long parseToken(String token){
        return 1L;
    }
}
